home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher+1.2b4 / gopherd / gopherindex.raw < prev    next >
Encoding:
Text File  |  1993-04-15  |  3.6 KB  |  220 lines

  1. #!/bin/sh
  2.  
  3. export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)
  4.  
  5. #
  6. #Set up variables
  7. #
  8. USAGE="$0: usage: $0 -wais waisargs -t next|wais -N 'long link name' datadir"
  9. gopherhome=GHOME
  10. indextype=ITYPE
  11. verbose=0
  12. indexname="Index of files in this directory"
  13. waisargs=""
  14. useinplaceindex=0
  15. Indexdir="moo"
  16.  
  17. # Parse args.
  18. while true ; do
  19.     case "$1" in
  20.         -t )
  21.     shift
  22.     if [ ! ${1-""} ] ; then    
  23.         echo $USAGE 1>&2
  24.         exit 1
  25.     fi
  26.            indextype="$1"
  27.         shift
  28.         ;;
  29.  
  30.     -a )
  31.     useinplaceindex=1
  32.     shift
  33.     ;;
  34.  
  35.     -N )
  36.     shift
  37.     if [ ! "${1}" ] ; then    
  38.         echo $USAGE 1>&2
  39.         exit 1
  40.     fi
  41.            indexname="$1"
  42.     shift
  43.     ;;
  44.  
  45.     -i )
  46.     shift
  47.     if [ ! "${1}" ] ; then    
  48.         echo $USAGE 1>&2
  49.         exit 1
  50.     fi
  51.            Indexdir="$1"
  52.     shift
  53.     ;;
  54.  
  55.     -wais )
  56.     shift
  57.     if [ ! "${1}" ] ; then    
  58.         echo $USAGE 1>&2
  59.         exit 1
  60.     fi
  61.     waisargs="$1"
  62.     shift
  63.     ;;
  64.  
  65.     -v )
  66.     verbose=1
  67.     shift
  68.     ;;
  69.  
  70.     -D )
  71.     set -x
  72.     shift
  73.     ;;
  74.         -* )
  75.         echo "$USAGE" 1>&2
  76.         exit 1
  77.         ;;
  78.         * )
  79.         break
  80.         ;;
  81.     esac
  82. done
  83.  
  84. #
  85. # Now we have the directory
  86. #
  87.  
  88. #
  89. # Find out if it's a relative path
  90. #
  91.  
  92. if (cd /;cd "$1") ; then
  93.     Datadir="$1"
  94. else
  95.     Datadir="$PWD/$1"
  96. fi
  97.  
  98.  
  99. #
  100. # Set the indexdir if it isn't set
  101. #
  102.  
  103. if [ $Indexdir = "moo" ]; then
  104.     Indexdir=$Datadir
  105. fi
  106.  
  107.  
  108. #
  109. # Find the path relative to the gopher-root (for Path= line)
  110. #
  111.  
  112. Pathdir=`echo "$Indexdir" | sed "s.$gopherhome.."`
  113.  
  114. if test "$verbose" = "1" ; then
  115.     echo "Gopher Home directory is $gopherhome"
  116.     echo "Indexes are hidden in $Indexdir"
  117.     echo "Indexing files in $Datadir"
  118. fi
  119.  
  120.  
  121. ################################################################
  122.  
  123. nextindex() {    
  124.     #
  125.     # See if it's writable
  126.     #
  127.     if test ! -w "$gopherhome" ;  then
  128.         echo "Sorry, can't write to $gopherhome"
  129.         exit 1;
  130.     fi
  131.  
  132.     if test -h "$gopherhome/.index" ; then
  133.         echo "Another indexing job is probably running"
  134.         echo "Check the link $gopherhome/.index"
  135.         exit 1
  136.     fi
  137.  
  138.     mkdir /tmp/gopherindex$$
  139.     mkdir /tmp/gopherindex$$/.index
  140.     mkdir "$Datadir/.index"
  141.     ln -s /tmp/gopherindex$$/.index "$gopherhome/.index"
  142.  
  143.  
  144.     if [ $useinplaceindex = 1 ]; then
  145.         cp "$Datadir/.index/index.ixif" "/tmp/gopherindex$$/.index"
  146.     fi
  147.  
  148.     if test $verbose = 1 ; then
  149.         ixargs="-Vv"
  150.     else
  151.         ixargs=""
  152.     fi
  153.     
  154.     ixargs="$ixargs -f ascii -i $gopherhome/.index/index.ixif"
  155.  
  156.     cd $gopherhome
  157.     ixBuild $ixargs "$Datadir"
  158.  
  159.     mv /tmp/gopherindex$$/.index/index.ixif "$Datadir/.index"
  160.     rm -rf  "/tmp/gopherindex$$"
  161.     rm "$gopherhome/.index"
  162.  
  163.     #
  164.     # Make the link
  165.     #
  166.     echo "Name=$indexname" >  "$Datadir/.IndexLink"
  167.     echo "Numb=1"           >> "$Datadir/.IndexLink"
  168.     echo "Type=7"          >> "$Datadir/.IndexLink"
  169.     echo "Host=+"          >> "$Datadir/.IndexLink"
  170.     echo "Port=+"            >> "$Datadir/.IndexLink"
  171.     echo "Path=7$Pathdir"   >> "$Datadir/.IndexLink"
  172. }
  173.  
  174.  
  175. waisindexer() {
  176.     mkdir "$Indexdir/.waisindex$$"
  177.  
  178.     if [ $useinplaceindex = 1 ]; then
  179.         cp "$Indexdir/.waisindex/"* "$Indexdir/.waisindex$$"
  180.     fi
  181.  
  182.     if test $verbose = 1 ; then
  183.         waisargs="$waisargs"
  184.     else
  185.         waisargs="$waisargs -l 2"
  186.     fi
  187.  
  188.     
  189.     cd "$Indexdir/.waisindex$$"
  190.     find "$Datadir" -type f -print | \
  191.         grep -v '/\.' |waisindex -stdin $waisargs
  192.  
  193.     #
  194.     # Make the link
  195.     #
  196.     echo "Name=$indexname"                  >  "$Datadir/.IndexLink"
  197.     echo "Numb=1"                           >> "$Datadir/.IndexLink"
  198.     echo "Type=7"                           >> "$Datadir/.IndexLink"
  199.     echo "Host=+"                           >> "$Datadir/.IndexLink"
  200.     echo "Port=+"                             >> "$Datadir/.IndexLink"
  201.     echo "Path=7$Pathdir/.waisindex/index"  >> "$Datadir/.IndexLink"
  202.  
  203.     rm -rf    "$Indexdir/.waisindex"
  204.     mv "$Indexdir/.waisindex$$" "$Indexdir/.waisindex"
  205. }
  206.  
  207.  
  208.  
  209.  
  210. if [ "$indextype" = "next" ]; then 
  211.     nextindex
  212. else
  213.     #
  214.     #Must be WAIS instead
  215.     #
  216.     waisindexer
  217. fi
  218.  
  219. exit 0
  220.